
//dd爱旋转
//操作方案：1.将矩阵顺时针旋转180度 2.水平镜像矩阵
const int N = 1100;
int arr[N][N] = { 0 };
int n = 0;
void SwapRow()
{
    int up = 0;
    int down = n - 1;
    while (up < down)
    {
        for (int i = 0;i < n;++i)
        {
            std::swap(arr[up][i], arr[down][i]);
        }
    }
}
void SwapCol()
{
    int left = 0;
    int right = n - 1;
    while (left < right)
    {
        for (int i = 0;i < n;++i)
        {
            std::swap(arr[i][left], arr[i][right]);
        }
    }
}

int main()
{
    for (int i = 0;i < n;++i)
    {
        for (int j = 0;j < n;++j)
        {
            cin >> arr[i][j];
        }
    }
    int q = 0;
    cin >> q;
    int row = 0, col = 0;
    while (q--)
    {
        int x = 0;
        cin >> x;
        if (1 == x) {
            ++row, ++col;
        }
        else if (2 == x) {
            ++row;
        }
    }
    row %= 2;
    col %= 2;
    if (row) {
        SwapRow();
    }
    if (col) {
        SwapCol();
    }
    for (int i = 0;i < n;++i)
    {
        for (int j = 0;j < n;++j)
        {
            cout << arr[i][j];
            if (j != n - 1){
                cout << " ";
            }
        }
        if (i != n - 1) {
            cout << endl;
        }
    }
    return 0;
}